const tagsView = {
    state: {
        visitedViews: [
            {title: '首页', path: '/index',}
        ],
    },

    mutations: {
        ADD_VISITED_VIEW: (state, tag) => {
            if (state.visitedViews.some(t => t.path === tag.path)) return
            state.visitedViews.push(
                Object.assign({}, tag)
            )
        },
        DEL_VISITED_VIEW: (state, tag) => {
            if (tag.path === '/index') return
            var index = state.visitedViews.indexOf(tag);
            state.visitedViews.splice(index, 1);
        },
        CLEAR_VISITED_VIEW: (state, tag) => {
            state.visitedViews = []
            state.visitedViews.push({title: '首页', path: '/index',})
        },
    },

    actions: {
        addVisitedView({commit}, tag) {
            commit('ADD_VISITED_VIEW', tag)
        },
        delVisitedView({commit}, tag) {
            commit('DEL_VISITED_VIEW', tag)
        },
        clearVisitedView({commit}) {
            commit('CLEAR_VISITED_VIEW')
        },
    }
}

export default tagsView
